<?php

namespace App\Http\Controllers\Estate;

use App\Http\Controllers\Controller;
use App\Models\Property;
use App\Services\UserService;
use Illuminate\Http\Request;

/**
 * Class PropertyController
 * @package App\Http\Controllers\Estate
 * 2021/3/17 - 16:22
 * Administrator
 * 物业信息
 */
class PropertyController extends Controller
{
    public $model;

    /**
     * PropertyController constructor.
     */
    public function __construct()
    {
        $this->model = new Property();
    }

    /**
     * 2021/3/17--16:20
     * @param $id
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:edit
     * @effect:编辑
     */
    public function edit()
    {
        $userService = new UserService();
        $info = $userService->getUserInfo('estate');
        return $this->success($this->model->getInfoById($info['estate_id']));
    }

    /**
     * 2021/3/17--16:21
     * @param Request $request
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:update
     * @effect:修改
     */
    public function update(Request $request)
    {
        $data = $request->post();

        if ($data['password'] == null) unset($data['password']);
        else $data['password'] = md5($data['password']);

        unset($data['create_time']);

        return $this->model->updateById($data['id'], $data) ? $this->success('修改成功!') : $this->error('修改失败!');
    }

    /**
     *析构方法
     */
    public function __destruct()
    {
        $this->model;
    }
}
